
Imports cmplib01


'// when opened, if the flag "emptyparent" = true then when can deploy RIGHT from here! Or we can simply ADD this one to the current bg


Public Class frmSelectOOB

    Private ptrGame As CampaignerGameData
    Private ptrDepZone As DeploymentZone
    Private _moveTypes() As String
    Private _actionCancelled As Boolean = False
    Private _selectedBG As BattlegroupChit
    Private _DeployAsBaseGroup As Boolean = False

    Public Shadows Sub ShowDialog(ByRef game As CampaignerGameData, ByRef moveTypes As String(), ByRef DepZone As DeploymentZone, Optional ByVal emptyParent As Boolean = True)
        ptrGame = game
        ptrDepZone = DepZone
        _moveTypes = moveTypes
        ListOOB()
        ListPVs()

        btnDeploy.Enabled = emptyParent

        MyBase.ShowDialog()
    End Sub

    Public ReadOnly Property DeployAsBaseGroup() As Boolean
        Get
            Return _DeployAsBaseGroup
        End Get
    End Property

    Private Sub ListOOB()
        Try
            Dim bg As BattlegroupChit

            For Each bg In ptrGame.selectedFaction.OrderOfBattle
                Dim tv As New CampaignerItemTreeNode
                tv.Item = bg
                tv.Text = bg.Name
                tv.ItemType = CampaignerItem_cgd.Battlegroup
                tvwOOB.Nodes.Add(tv)
            Next

        Catch ex As Exception
            HandleException("frmSelectOOB.ListOOB", ex)
        End Try
    End Sub

    Private Sub ListPVs()
        Try
            lblFactionPV.Text = ptrGame.selectedFaction.FactionFreePoints
            lblDepZonePV.Text = ptrDepZone.MaxTotalDeploy
        Catch ex As Exception
            HandleException("frmSelectOOB.ListPVs", ex)
        End Try
    End Sub

    Private Sub tvwOOB_AfterSelect(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles tvwOOB.AfterSelect
        '// we list the units in this BG, by NUMBER of units? Like, 16 infantry, 4 tanks, etc
        Try

            If tvwOOB.SelectedNode Is Nothing Then Exit Sub

            Dim bg As BattlegroupChit = DirectCast(tvwOOB.SelectedNode, CampaignerItemTreeNode).Item

            lstUnits.Items.Clear()

            Dim un As ChitMember
            For Each un In bg.members
                lstUnits.Items.Add(un.Name)
            Next

            bg.CalculateProperties()

            '// show the properties of this mutha sukka
            picBG.BackgroundImage = bg.icon
            lblPointValue.Text = bg.SuggestedPointValue
            lblMoveSpeed.Text = bg.MovementSpeed
            lblMType.Text = _moveTypes(bg.MovementClassID)

            _selectedBG = bg

        Catch ex As Exception
            HandleException("frmSelectOOB.tvwOOB_AfterSelect", ex)
        End Try
    End Sub

    Public Property SelectedBG() As BattlegroupChit
        Get
            Return _selectedBG
        End Get
        Set(ByVal value As BattlegroupChit)
            _selectedBG = value
        End Set
    End Property

    Private Sub btnOK_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOK.Click
        If _selectedBG Is Nothing Then
            _actionCancelled = True
        Else
            _actionCancelled = False
        End If

        _DeployAsBaseGroup = False
        Me.Hide()
    End Sub

    Private Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        _actionCancelled = True
        Me.Hide()
    End Sub

    Public ReadOnly Property ActionCancelled() As Boolean
        Get
            Return _actionCancelled
        End Get
    End Property

    Private Sub btnDeploy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeploy.Click

        If _selectedBG Is Nothing Then
            _actionCancelled = True
        Else
            _actionCancelled = False
        End If

        _DeployAsBaseGroup = True
        Me.Hide()
    End Sub
End Class